package com.gs.djys.bigpic;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.gs.djys.Base.Urls;
import com.gs.djys.R;
import com.gs.djys.Util.ToastUtils;
import com.gs.djys.Util.Utils;
import com.gs.djys.mvp.MVPBaseActivity;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.FileCallback;
import com.lzy.okgo.model.Response;

import java.io.File;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class BigPicActivity extends MVPBaseActivity<BigPicContract.View, BigPicPresenter> implements BigPicContract.View {

    @Bind(R.id.img)
    ImageView img;
    @Bind(R.id.backs)
    RelativeLayout backs;
    @Bind(R.id.layout)
    RelativeLayout layout;
    private String pic;

    @Override
    public void onRequestError(String msg) {
        ToastUtils.showShortToast(msg);
    }

    @Override
    protected int getLayout() {
        return R.layout.act_bigpic;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        Bundle bundle = getIntent().getExtras();
        pic = bundle.getString("pic");
        OkGo.<File>get(Urls.SERVER + "/road/lictran/file/viewImgForApp?KEY=" + pic)
                .execute(new FileCallback() {
                    @Override
                    public void onSuccess(Response<File> response) {
                        if(!Utils.isDestroy(BigPicActivity.this)){
                            Glide.with(BigPicActivity.this)
                                    .asBitmap()
                                    .load(response.body())
                                    .into(img);
                        }
                    }
                });
        backs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
